package com.wsp.service.util;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Package: com.wsp.service.util
 * Description： TODO
 *
 * @Author: 巫思平
 * Copyright: Copyright (c) 2020
 * Version: 1
 */
public class LockKeepLiveUtil implements Runnable {
    public static final ConcurrentHashMap<Thread,String> LIVE_TASK = new ConcurrentHashMap<>();
    private RedisUtil redisUtil = null;
    @Override
    public void run() {
        for (Map.Entry<Thread, String> entry : LIVE_TASK.entrySet()) {
            if (entry.getKey().isAlive()) {
                if (!redisUtil.expire(entry.getValue())) {
                    LIVE_TASK.remove(entry.getKey());
                }
            } else {
                LIVE_TASK.remove(entry.getKey());
            }
        }
    }


    public void setRedisUtil(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }
}
